<template>
	<view class="tabbarpage-container">
		<!--胶囊上方-->
		<div :style="{'padding-top': statusBarHeight}">
			
		</div>
		<!--胶囊-->
		<div class="head-container" :style="{'height': capsuleHeight}">
			拍照识题
		</div>
		<!--主体-->
		<div class="tabbarpage-body" >
			<!--相机区域-->
			<div class="camera-container">
				<!-- #ifdef MP-WEIXIN -->
				<camera device-position="back" flash="off" @error="error" style="width: 100%; height: 100%;"></camera>
				<!-- #endif -->
				<!-- #ifdef APP-PLUS -->
				<view style="width: 100%; height: 100%; background-color: #000;" color="white"></view>
				<!-- #endif -->
			</div>
			<div class="line-container">
				<div class="line"></div>
				<div class="line"></div>
			</div>
			<div class="line1-container">
				<div class="line1"></div>
				<div class="line1"></div>
			</div>
			<!--拍照按钮-->
			<div class="btn-container">
				<div @click="getPhoto" class="btn">相册</div>
				<wd-img @click="takePhoto" round height="58px" width="58px" src="https://www.yym-free.com/resource/default/png/28ebbe52-773c-4230-a9db-6648a9115ab2.png"></wd-img>
				<div class="btn" @click="cancleCamera">取消</div>
			</div>
			<!--底部tabbar占据高度72px-->
		</div>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { globalProps } from '@/js/global.js'
	import {currentOCR} from '@/js/ques.js'
	
	const statusBarHeight = ref(globalProps.statusBarHeight)
	const capsuleHeight = ref(globalProps.capsuleHeight)
	
	const error = (e)=>{
		console.log(e)
	}
	const cancleCamera = ()=>{
		uni.navigateBack()
	}
	const photo = ref('')
	const takePhoto = ()=>{
		// #ifdef MP-WEIXIN
		const ctx = uni.createCameraContext();
		ctx.takePhoto({
		    quality: 'normal',
		    success: (res) => {
		        photo.value = res.tempImagePath
				pageJump(photo.value)
		    }
		});
		// #endif
		// #ifdef APP-PLUS
		const camera = plus.camera.getCamera();
		camera.captureImage((path)=>{
			photo.value = path
			pageJump(photo.value)
		},(error)=>{
			console.log('拍照失败')
		},{filename:'_doc/camera/'});
		// #endif
	}
	const getPhoto = ()=>{
		uni.chooseImage({
			count:1,
			sizeType:['compressed'],
			sourceType:['album'],	//调用原生相册和原生相机，弹出选择
			success:(res)=>{
				photo.value = res.tempFilePaths[0]
				pageJump(photo.value)
			}
		})
	}
	//页面跳转
	const pageJump = (file)=>{
		uni.navigateTo({
				url: '/pages/newques/CameraCutPage/CameraCutPage?photo=' + encodeURIComponent(file)
		    });
	}
</script>

<style>
	@import "@/css/global.css";
	@import "@/css/animation.css";
	.head-container{
		display: flex;
		align-items: center;
		justify-content: center;
		color: white;
		letter-spacing: 1px;
	}
	.camera-container{
		position: absolute;
		left: 0;
		top: 12px;
		right: 0;
		bottom: 80px;
	}
	.line-container{
		position: absolute;
		left: 0;
		top: 12px;
		right: 0;
		bottom: 80px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		flex-direction: column;
		animation: left-in-ani .6s 1;
	}
	.line-container .line{
		width: 100%;
		height: 1px;
		background-color: #eeeeee22;
	}
	.line1-container{
		position: absolute;
		left: 0;
		top: 12px;
		right: 0;
		bottom: 88px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		animation: top-in-ani .6s 1;
	}
	.line1-container .line1{
		width: 1px;
		height: 100%;
		background-color: #eeeeee22;
	}
	.btn-container{
		position: absolute;
		left: 0;
		right: 0;
		bottom: 12px;
		height: 60px;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}
	.btn-container .btn{
		color: #fff;
		width: 80px;
		text-align: center;
		letter-spacing: 1px;
		font-size: 17px;
	}
</style>
